package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class TestAspect {

    @Before("execution(* com.itheima.service.*.*(..))")
    public  void before(){
        log.info("前置通知");
    }


    @Around("execution(* com.itheima.service.*.*(..))")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("环绕通知的前置,相当于前置通知");
        Object result = proceedingJoinPoint.proceed();
        log.info("环绕通知的后置,相当于最终通知");
        return  result;
    }
    @After("execution(* com.itheima.service.*.*(..))")
    public  void after(){
        log.info("后置通知，此注解标注的通知方法在目标方法后被执行，无论是否有异常都会执行");
    }
    @AfterReturning("execution(* com.itheima.service.*.*(..))")
    public  void afterReturning(){
        log.info("返回后通知，此注解标注的通知方法在目标方法后被执行，有异常不会执行");
    }
    @AfterThrowing("execution(* com.itheima.service.*.*(..))")
    public  void afterThrowing(){
        log.info("异常后通知，此注解标注的通知方法发生异常后执行");
    }
}
